﻿using System.IO;
using System.Text.RegularExpressions;

namespace Sustainalytics.Utils
{
    public class RemoveIllegalCharacters
    {
        public static string Replace(string inputText, string replaceWith)
        {
            string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
            Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
            inputText = r.Replace(inputText, replaceWith);

            return inputText.Replace(" ", replaceWith);
        }

        public static string Remove(string inputText)
        {
            string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
            Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
            inputText = r.Replace(inputText, "");

            return inputText.Replace(" ", "");
        }
    }
}
